package mumu.android.view;

import java.util.ArrayList;
import java.util.List;

import mumu.android.R;
import mumu.android.lib.view.DotView;
import mumu.android.lib.view.GridViewPager;
import mumu.android.lib.view.GridViewPager.IWatchInterface;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class gridviewpager extends Activity {
	GridViewPager<Integer> vP;
	Button btn;
	int column = 4;
	int rows = 4;
	// ChannelAdapter apdAdapter;
	// List<View> mListViews = new ArrayList<View>();
	int width, height;
	Boolean has = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.viewpager);
		vP = (GridViewPager<Integer>) findViewById(R.id.vp);
		btn = (Button) findViewById(R.id.btn);
		DotView dv_channel = (DotView) findViewById(R.id.dv);
		final List<Integer> integers = new ArrayList<Integer>();
		integers.add(R.drawable.ll4);
		integers.add(R.drawable.ll2);
		integers.add(R.drawable.ll5);
		integers.add(R.drawable.ll2);
		integers.add(R.drawable.ll3);
		integers.add(R.drawable.ll4);
		integers.add(R.drawable.ll5);
		integers.add(R.drawable.ll1);
		integers.add(R.drawable.ll4);
		integers.add(R.drawable.ll2);
		integers.add(R.drawable.ll5);
		integers.add(R.drawable.ll5);
		integers.add(R.drawable.ll4);
		integers.add(R.drawable.ll2);
		integers.add(R.drawable.ll3);
		integers.add(R.drawable.ll5);
		integers.add(R.drawable.ll4);
		integers.add(R.drawable.ll3);
		integers.add(R.drawable.ic_launcher);
		// integers.add(R.drawable.l4);
		// integers.add(R.drawable.title_bm);
		// integers.add(R.drawable.title_bg);
		// integers.add(R.drawable.btn_1);
		// integers.add(R.drawable.btn_2);
		
		vP.createView(new IWatchInterface<Integer>() {

			@Override
			public View gvGetView(Integer t, int position, int itemWidth, int itemHeight) {
				View convertView = LayoutInflater.from(gridviewpager.this).inflate(R.layout.home_fragment_channel_item, null);
				ImageView img = (ImageView) convertView.findViewById(R.id.img_logo);
				img.setImageResource(t);
				LayoutParams lp = img.getLayoutParams();
				img.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						Toast.makeText(gridviewpager.this, "width height", 1000).show();
					}
				});
				lp.width = itemWidth;
				lp.height = itemHeight;
				return convertView;
			}
		}, column, rows, integers);
		dv_channel.initView(5, 0, true);
		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				int tem = column;
				int rowtem = rows;
				if (rows == 4) {
					rowtem = 2;
					tem = 2;
				} else if (rows == 2) {
					tem = 2;
					rowtem = 1;
				} else if (rows == 1) {
					rowtem = 4;
					tem = 4;
				}
				rows = rowtem;
				column = tem;
				Toast.makeText(gridviewpager.this, "dd" + width + " " + height, 1000).show();
				vP.notifyDataSetChanged(tem, rowtem, integers);

				// CataLogView cataLogView = new CataLogView();
				// cataLogView.onCreateView(ViewPagerActivity.this);
				// cataLogView.showPopWindow();
			}
		});
	}

}
